package com.czbank.financing.utils;

import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import com.czbank.financing.Entity.UserInfo;
import org.junit.jupiter.api.Test;

import java.io.UnsupportedEncodingException;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @Auther: thinkpad
 * @Date: 2019/7/14 09:49
 * @Description:
 */
public class JwtUtil {

    /*
    生成签名
     */
    public static final long EXPRIE_TIME=15*60*1000;

    public static final String TOKEN_SECRET = "ads656d5as41f654asfsad231ads";

    public String getToken(UserInfo userInfo) throws UnsupportedEncodingException {
        String token = "";
        token = JWT.create().withAudience(String.valueOf(userInfo.getId())).sign(Algorithm.HMAC256(userInfo.getPassword()));

        return token;
    }

    /*public static String sign(String username){

            try {
                Date date = new Date(System.currentTimeMillis()+EXPRIE_TIME);
                Algorithm algorithm = Algorithm.HMAC256(TOKEN_SECRET);
                Map<String,Object> header = new HashMap<>(2);
                header.put("typ","JWT" );
                header.put("alg","HS256" );
                return JWT.create()
                        .withHeader(header)
                        .withClaim("loginName", username)
                        .withExpiresAt(date)
                        .sign(algorithm);
            } catch (UnsupportedEncodingException e) {
                return null;
            }

    }
*/



}
